package parser

import (
	"gxgeek.com/gxgeek/learngo/crawler/engine"
	"regexp"
	"gxgeek.com/gxgeek/learngo/crawler/config"
)

const regexpString = `<a href="(http://www.zhenai.com/zhenghun/[0-9a-z]+)"[^>]*>([^<]+)</a>`


func ParseCityList(contents []byte,_ string) engine.ParseResult {
	compile := regexp.MustCompile(regexpString)
	match := compile.FindAllSubmatch(contents, -1)
	result := engine.ParseResult{}
	for _, s := range match {
		result.Requests = append(
			result.Requests,
			engine.Request{
				Url: string(s[1]),
				Parser: engine.NewFuncParser(
					ParseCity,
					config.ParseCity),
			},
		)

	}
	return result
}
